package com.yic.module.system.dal.mysql.code;

import java.util.*;

import com.yic.framework.common.pojo.PageResult;
import com.yic.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yic.framework.mybatis.core.mapper.BaseMapperX;
import com.yic.module.system.controller.admin.code.vo.CodeRuleExportReqVO;
import com.yic.module.system.controller.admin.code.vo.CodeRulePageReqVO;
import com.yic.module.system.dal.dataobject.code.CodeRuleDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 编号规则明细 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface CodeRuleMapper extends BaseMapperX<CodeRuleDO> {

    default PageResult<CodeRuleDO> selectPage(CodeRulePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CodeRuleDO>()
                .eqIfPresent(CodeRuleDO::getType, reqVO.getType())
                .eqIfPresent(CodeRuleDO::getParam, reqVO.getParam())
                .eqIfPresent(CodeRuleDO::getEdit, reqVO.getEdit())
                .eqIfPresent(CodeRuleDO::getSerial, reqVO.getSerial())
                .eqIfPresent(CodeRuleDO::getCodeId, reqVO.getCodeId())
                .betweenIfPresent(CodeRuleDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CodeRuleDO::getId));
    }

    default List<CodeRuleDO> selectList(CodeRuleExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<CodeRuleDO>()
                .eqIfPresent(CodeRuleDO::getType, reqVO.getType())
                .eqIfPresent(CodeRuleDO::getParam, reqVO.getParam())
                .eqIfPresent(CodeRuleDO::getEdit, reqVO.getEdit())
                .eqIfPresent(CodeRuleDO::getSerial, reqVO.getSerial())
                .eqIfPresent(CodeRuleDO::getCodeId, reqVO.getCodeId())
                .betweenIfPresent(CodeRuleDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CodeRuleDO::getId));
    }

    default Integer deleteByCodeId(Long codeId) {
        return delete(new LambdaQueryWrapperX<CodeRuleDO>()
                .eq(CodeRuleDO::getCodeId, codeId));

    }

    default List<CodeRuleDO> selectByCodeId(Long codeId) {
        return selectList(new LambdaQueryWrapperX<CodeRuleDO>()
                .eq(CodeRuleDO::getCodeId, codeId));
    }
}
